import { defineConfig } from 'vite'
import { sharedConfig } from './vite.config'
import { isDev, r } from './scripts/utils'
import packageJson from './package.json'

// bundling the content script using Vite
export default defineConfig({
  ...sharedConfig,
  define: {
    '__DEV__': isDev,
    '__NAME__': JSON.stringify(packageJson.name),
    // https://github.com/vitejs/vite/issues/9320
    // https://github.com/vitejs/vite/issues/9186
    'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
  },
  build: {
    watch: isDev
      ? {}
      : undefined,
    outDir: r('extension/dist/contentScripts'),
    cssCodeSplit: false,
    emptyOutDir: false,
    sourcemap: isDev ? 'inline' : false,
    lib: {
      entry: r('src/contentScripts/index.ts'),
      name: packageJson.name,
      formats: ['iife'],
    },
    rollupOptions: {
      output: {
        entryFileNames: 'index.global.js',
        extend: true,
      },
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        modifyVars: {
          'zindex-badge': 'auto',
          'zindex-table-fixed': 99999000003,
          'zindex-affix': 9999900010,
          'zindex-back-top': 9999900010,
          'zindex-picker-panel': 9999900010,
          'zindex-popup-close': 9999900010,
          'zindex-modal': 999990999990,
          'zindex-modal-mask': 999990999990,
          'zindex-message': 9999901010,
          'zindex-notification': 9999901010,
          'zindex-popover': 9999901030,
          'zindex-dropdown': 9999901050,
          'zindex-picker': 9999901050,
          'zindex-popoconfirm': 9999901060,
          'zindex-tooltip': 9999901070,
          'zindex-image': 9999901080,
          '@ant-prefix': "xc-ant",
          '@iconfont-css-prefix':"xc-icon",
        },
      },
    },
    // postcss: {
    //   plugins: [
    //     require('autoprefixer'),
    //     // require('postcss-prefix-selector')({
    //     //   prefix: '#XCSJ_CONTAINER ',
    //     //   ignore:[':not(.ant-input-affix-wrapper)'],
    //     // }),
    //   ]
    // }
  },
})
